﻿#include "stream/push_stream.h"

namespace xrtc {

PushStream::PushStream(XRTCPusher* xrtc_pusher,std::string uid, const std::string& stream_name) :
    WebRTCStream(xrtc_pusher,uid, stream_name)
{
}

PushStream::~PushStream() {
}

void PushStream::AddAudioTrack() {
    if (!pc || !pc_factory) {
        return;
    }

    cricket::AudioOptions audio_options;

    rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
        pc_factory->CreateAudioTrack("audio_label",
            pc_factory->CreateAudioSource(audio_options)));
    auto result_or_error = pc->AddTrack(audio_track, { "stream_id" });
    if (!result_or_error.ok()) {
        RTC_LOG(LS_WARNING) << "failed to add audio track to peerconnection: "
            << result_or_error.error().message();
    }
}

void PushStream::AddVideoTrack(
    webrtc::VideoTrackSourceInterface* video_source) 
{
    if (!pc || !pc_factory) {
        return;
    }

    rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
        pc_factory->CreateVideoTrack("video_label", video_source));
    auto result_or_error = pc->AddTrack(video_track, { "stream_id" });
    if (!result_or_error.ok()) {
        RTC_LOG(LS_WARNING) << "failed to add audio track to peerconnection: "
            << result_or_error.error().message();
    }
}

} // namespace xrtc